<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include 'sections/head.phtml'; ?>
</head>
<body id="computer" class="root4">
<?php include 'sections/header.phtml'; ?>
<div class="clearfix"></div>
<div id="container" class="w"> 
  <!-- SIDE BAR -->
  <?php include 'sections/sidebar.phtml'; ?>
<!-- MAIN CONTENT AREA -->
<div id="content-area">
  <div id="m-bcrm" class="clearfix">
    <?php //echo breadcrumb::newInstance()->render(); ?>
  </div>
  <div class="error_message" style="color:#f90;">
    <?php 
  $msgs=Session::newInstance()->_getMessage('post_error');
  $msgs=@$msgs['msg'];
  if($msgs){
  	foreach($msgs as $msg){
  		echo '<p>'.$msg.'</p>';
  	}	
  }
  ?>
  </div>
  <form action="<?php echo site_url(); ?>item/post/" style="margin:20px;" method="post" enctype="multipart/form-data">
    <div id="category_location">
      <select name="category_id" id="category_id">
        <option value="0">Select Category</option>
        <?php 
		
		$previous=0;
		$values=View::newInstance()->_get('form');
		if(isset($values['category_id'])){
			$previous=$values['category_id'];
		}
		
		echo Helper_Categories::newInstance()->createOption('',$previous);?>
      </select>
      <select name="location_id">
        <option value="0">Select Location</option>
        <?php 
        $pre_location=0;
        if(isset($values['location_id'])){
        	$pre_location=$values['location_id'];
        }
        echo Helper_Location::newInstance()->createOption('',$pre_location); ?>
      </select>
    </div>
    <div id="ad_type_container"> </div>
    <br />
    <span>Title</span><br />
    <input type="text" name="name" size="50" value="<?php  echo @$values['name']; ?>" />
    <br />
    <br />
    <span>Urgent?</span>
    <input type="checkbox" name="urgent" <?php if(@$values['urgent']) echo 'checked="checked"'; ?> />
    <br />
    <br />
    <span>Price</span><br />
    <input type="text" name="price" size="25" value="<?php if(@$values['price']) echo $values['price']; ?>" />
    <br />
    <br />
    <span>Description</span><br />
    <textarea name="description" rows="10" cols="46" class="tiny_mce"><?php if(@$values['description']) echo $values['description']; ?>
</textarea>
    <br />
    <span>Local Area</span><br />
    <input type="text" name="local_area" size="25" <?php if(@$values['local_area']) echo $values['local_area']; ?> />
    <br />
    <span>Postcode</span><br />
    <input type="text" name="postcode" size="25" <?php if(@$values['postcode']) echo $values['postcode']; ?> />
    <br />
    <span>Use Postcode in Map?</span><br />
    <input type="checkbox" name="use_in_map" checked="checked" <?php if(@$values['use_in_map']) echo 'checked="checked"'; ?> />
    <br />
    
    <div id="image_upload">
    <span>Image</span><br />
      <input type="file" name="image" />
    </div>
    <span>Youtube URL</span><br />
    <input type="text" name="youtube_url" size="50" <?php if(@$values['youtube_url']) echo $values['youtube_url']; ?> />
    <br />
    <br />
    <div id="category_field_container">
    
    </div>
    <br />
    <br />
    <?php if(!user_logged_in ()){ ?>
    <div id="user_login">
      <input type="radio" name="register" class="toggle_button" value="no" rel="login_section" checked="checked" />
      I already have an account.
      <input type="radio" name="register" rel="register_section" class="toggle_button" value="yes" />
      I do not have an account. <br />
      <div id="login_section"> <span>Email:</span><br />
        <input type="text" name="email"  size="35" <?php if(isset($values['email'])) echo $values['email']; ?> />
        <br />
        <span>Password:</span><br />
        <input type="password" name="password"  size="35"  />
      </div>
    </div>
    <?php } ?>
    <br />
    <input type="submit" name="submit" value="Continue" />
  </form>
</div>
<span class="clearfix"></span>
<?php include 'sections/footer.phtml'; ?>
<script type="text/javascript" src="<?php echo content_url(); ?>tinymce/tiny_mce.js"></script> 
<script type="text/javascript">
$(document).ready(function(){
	$('#category_id').change(function(){
		 var id=$(this).val();
		 var url='<?php echo site_url()?>ajax/load-form/?id='+id;
		 if(id){
			$.get(url,function(data){
				var obj=jQuery.parseJSON(data);
				console.log(obj);
				$('#ad_type_container').html(obj.ad_type);
				console.log(obj.adtype);
				$('#category_field_container').html(obj.field);
				eval(obj.script);
				})
			 }
		});
	
});
tinyMCE.init({
        // General options
        mode : "specific_textareas",
        editor_selector : "tiny_mce",
        theme : "advanced",
        //plugins : "autolink,lists,spellchecker,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
		plugins : "lists,insertdatetime,preview,paste,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
		theme_advanced_text_colors :"",// "FF0000,FF00FF,FFFF00,000000",
        // Theme options
		theme_advanced_fonts :"",//Courier New=courier new,courier,sans-serif;Arial=arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;",
		theme_advanced_font_sizes :"", // "8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,24px,26px,28px,32px,34px,36px,40px,44px,48px,52px,60px,64px,68px,72px",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,bullist,numlist,|insertdate,inserttime,preview,",
        theme_advanced_buttons2 : "",//|,forecolor,backcolor,|,sub,sup,|,charmap|,fullscreen,",
        theme_advanced_buttons3 : "",//"tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Skin options
        skin : "o2k7",
        skin_variant : "silver",

        // Example content CSS (should be your site CSS)
        content_css : "",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "js/template_list.js",
        external_link_list_url : "js/link_list.js",
        external_image_list_url : "js/image_list.js",
        media_external_list_url : "js/media_list.js",

        // Replace values for the template plugin
        template_replace_values : {
                username : "Some User",
                staffid : "991234"
        }
		});
</script>
</body>
</html>